package com.oscar.ehome.view.pageview;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.DiaoChaActivity;
import com.oscar.ehome.base.fragment.BaseFragment;
import com.oscar.ehome.bean.UsersBean;
import com.oscar.ehome.bean.loginbean.UserBean;
import com.oscar.ehome.bean.pagebean.MingpianBean;
import com.oscar.ehome.bean.pagebean.PageListBean;
import com.oscar.ehome.bean.pagebean.PageMessageBean;
import com.oscar.ehome.bean.BannerBean;
import com.oscar.ehome.bean.pagebean.ShouyeOFOBean;
import com.oscar.ehome.bean.pagebean.YaoQingBean;
import com.oscar.ehome.presenter.PagePresenter;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.bannerview.ADInfo;
import com.oscar.ehome.utils.bannerview.ImageCycleView;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.AesUtils;
import com.oscar.ehome.utils.util.CommonUtils;
import com.oscar.ehome.utils.util.ToastUtil;
import com.oscar.ehome.utils.util.makeTime;
import com.oscar.ehome.utils.view.MyList;
import com.oscar.ehome.utils.xrefresh.XRefreshView;
import com.oscar.ehome.view.loginview.LoginActivity;
import com.oscar.ehome.view.messageview.MessageDetilActivity;
import com.oscar.ehome.view.pageview.adapter.PageListAdapter;
import com.oscar.ehome.view.pageview.adapter.PagesAdapter;
import com.oscar.ehome.view.pageview.view.PageBannerView;
import com.oscar.ehome.view.setview.SigninActivity;
import com.umeng.analytics.MobclickAgent;

import net.tycmc.bulb.androidstandard.utils.JsonUtils;

import org.apache.commons.collections.MapUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by on 2017/5/19 16:11.
 * 主页
 *
 * @author mengwanhe
 */
public class PageFragment extends BaseFragment<PageBannerView, PagePresenter> implements AdapterView.OnItemClickListener,
        PageBannerView, XRefreshView.XRefreshViewListener {
    /**
     * 轮播图
     */
    @BindView(R.id.ad_view)
    ImageCycleView adView;
    /**
     * 标题
     */
    @BindView(R.id.title_topbar)
    TextView titleTopbar;
    /**
     * 展示数据
     */
    @BindView(R.id.appl_gridview)
    GridView applGridview;
    /**
     * 增援图片
     */

    @BindView(R.id.ofolin)
    LinearLayout ofolin;
    @BindView(R.id.ofoimg)
    ImageView ofoimg;
    @BindView(R.id.ofotitle)
    TextView ofotitle;

    @BindView(R.id.title_img_right)
    ImageView titleImgRight;
    /**
     * 增员
     */
    @BindView(R.id.title_right_layput)
    RelativeLayout titleRightLayput;
    /**
     * list view
     */
    @BindView(R.id.page_listview)
    MyList pageListview;

    /**
     * title布局
     */
    @BindView(R.id.basetitle_bar)
    RelativeLayout basetitleBar;
    /**
     *
     */
    @BindView(R.id.page_xrefresh)
    XRefreshView pageXrefresh;
    /**
     * view
     */
    private View view;
    /**
     * banner图片
     */
    private ArrayList<ADInfo> infos = new ArrayList<ADInfo>();
    private List<BannerBean> bannerBean;
    /**
     * 应用管理数据
     */
    List<String> app_List = new ArrayList<>();
    List<PageListBean.PageBean> pageList = new ArrayList<>();
    ShouyeOFOBean bean;
    String token = "";
    UserBean userbean;
    UsersBean userBe;
    PagesAdapter adapter;
    int colnum = 5;//adapter 列数
    //查询数据调用
    private PagePresenter pagePresenter;
    PageListAdapter listAdapter;
    public static long lastRefreshTime;
    int size = 4;
    String name = "", touxiang = "";
    private AnimationDrawable animationDrawable;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_page, null);
        ButterKnife.bind(this, view);
        basetitleBar.setBackgroundColor(Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        OnClick();
        initView();
        initDatas();
        return view;
    }

    @Override
    protected PagePresenter createPresenter() {
        pagePresenter = new PagePresenter(this);
        return pagePresenter;
    }

    /**
     * 点击事件
     */
    public void OnClick() {
        ofolin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bean != null && !bean.equals("")) {
                    MobclickAgent.onEvent(getActivity(), "fashang");
                    Intent in = new Intent();
                    in.setClass(getActivity(), StudyActivity.class);
                    in.putExtra("id", bean.getId());
                    startActivity(in);
                }

            }
        });
        applGridview.setOnItemClickListener(this);
        pageListview.setOnItemClickListener(this);

        pageXrefresh.setXRefreshViewListener(this);
        // 设置是否可以下拉刷新
        pageXrefresh.setPullRefreshEnable(true);
        // 设置是否可以上拉加载
        pageXrefresh.setPullLoadEnable(false);
        //设置恒华不刷新
        pageXrefresh.setMoveForHorizontal(true);
        // 设置上次刷新的时间
        pageXrefresh.restoreLastRefreshTime(lastRefreshTime);
        //当下拉刷新被禁用时，调用这个方法并传入false可以不让头部被下拉
        pageXrefresh.setMoveHeadWhenDisablePullRefresh(true);
        // 设置时候可以自动刷新
        pageXrefresh.setAutoRefresh(false);

    }

    /**
     * 填充数据
     */
    public void initView() {
        titleRightLayput.setVisibility(View.VISIBLE);
        titleImgRight.setVisibility(View.VISIBLE);
        titleImgRight.setImageResource(R.mipmap.zengyuan);

        token = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getToken();

        String user = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getUserBean();
        userbean = new Gson().fromJson(user, UserBean.class);
        titleTopbar.setText(userbean.getCompany().getName());

        listAdapter = new PageListAdapter(getActivity(), pageList);

        pageListview.setAdapter(listAdapter);
        size = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getAppactionnum();

        adapter = new PagesAdapter(getActivity(), colnum, app_List, size);
        applGridview.setAdapter(adapter);

    }

    /**
     * 判断是否有网
     */
    public boolean isNetWork() {
        boolean netWork = true;
        if (!CommonUtils.isNetConn(getActivity())) {
            netWork = false;
            return netWork;
        }
        return netWork;
    }

    /**
     * 加载数据
     */
    public void initDatas() {
        if (isNetWork()) {
            initadapter();
            setImage();
            getList();
            getUsers();
        }
    }

    /**
     * 初始化adapter
     */
    public void initadapter() {
        pagePresenter.getAppactions(token);
    }

    /**
     * 添加banner图
     */
    public void setImage() {
        pagePresenter.banners(token);
    }

    /**
     * 添加列表
     */
    public void getList() {
        pagePresenter.getPageList(token);
        pagePresenter.getOFO(token);
    }

    /**
     * 获取个人信息
     */
    public void getUsers() {
        pagePresenter.getUser(token);

    }

    /**
     * 初始化adapter
     */
    public void initData() {
        String applist = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getAppaction();

        if (applist != null && !"".equals(applist)) {
            Map<String, Object> add_map = JsonUtils.fromJsonToHashMap(applist);
            app_List = (List<String>) MapUtils.getObject(add_map, "applist");
            adapter.setList(app_List, size);
        }
    }


    private ImageCycleView.ImageCycleViewListener mAdCycleViewListener = new ImageCycleView.ImageCycleViewListener() {

        @Override
        public void onImageClick(ADInfo info, int position, View imageView) {//图片点击事件
            BannerBean object1 = bannerBean.get(position);
            Intent intent = new Intent(getActivity(), BannerWebActivity.class);
            intent.putExtra("contentsrc", object1.getContentSrc());
            intent.putExtra("type", "banner");
            intent.putExtra("name", "");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getActivity().startActivity(intent);
        }

        @Override
        public void displayImage(String imageURL, ImageView imageView) {
            GildeUtils.loadUrlImages(imageURL, imageView, getActivity());
        }
    };

    @OnClick(R.id.title_right_layput)
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_right_layput://增员
                if (userBe != null) {
                    if (userBe.getIsPay() != null && "1".equals(userBe.getIsPay())) {
                        MobclickAgent.onEvent(getActivity(), "zengyuan1");
                        Intent intent = new Intent(getActivity(), AddMemberActivity.class);
                        intent.putExtra("twocode", "page");
                        startActivity(intent);
                    } else {
                        Toast.makeText(getActivity(), "请支付后进入", Toast.LENGTH_SHORT).show();
                    }
                }


                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (parent == applGridview) {

            if (size < 4 && position == size) {
                if (SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing() != null && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("")
                        && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("false")) {
                    Intent intent = new Intent(getActivity(), ApplationsActivity.class);
                    intent.putExtra("people", name);
                    intent.putExtra("touxiang", touxiang);
                    startActivity(intent);


                } else {
                    Intent intent = new Intent(getActivity(), ApplationsActivity.class);

                    startActivity(intent);
                }

            } else if (size >= 4 && position == colnum - 1) {
                if (SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing() != null && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("")
                        && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("false")) {
                    Intent intent = new Intent(getActivity(), ApplationsActivity.class);
                    intent.putExtra("people", name);
                    intent.putExtra("touxiang", touxiang);
                    startActivity(intent);


                } else {
                    Intent intent = new Intent(getActivity(), ApplationsActivity.class);

                    startActivity(intent);
                }
            } else {
                String stats = app_List.get(position);
                switch (stats) {
                    case "8"://应用中心
                        MobclickAgent.onEvent(getActivity(), "yingyongzhongxin");
                        Intent intent = new Intent(getActivity(), AppListActivity.class);
                        startActivity(intent);
                        break;
                    case "7"://考勤签到
                        MobclickAgent.onEvent(getActivity(), "kaoqinqiandao");
                        if (userBe != null) {
                            if (userBe.getIsPay() != null && "1".equals(userBe.getIsPay())) {
                                startActivity(new Intent(getActivity(), SigninActivity.class));
                            } else {
                                Toast.makeText(getActivity(), "请支付后进入", Toast.LENGTH_SHORT).show();
                            }
                        }
                        break;
                    case "6"://统计
                        MobclickAgent.onEvent(getActivity(), "tongji");
                        Intent intent_tj = new Intent(getActivity(), TeamCountNewActivity.class);
                        intent_tj.putExtra("member_name", userbean.getName());
                        intent_tj.putExtra("id", SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getUuid());
                        startActivity(intent_tj);
                        break;
                    case "9"://准会员
                        MobclickAgent.onEvent(getActivity(), "zhunhuiyuan");
                        Intent intent_member = new Intent(getActivity(), MembersListActivity.class);
                        startActivity(intent_member);
                        break;
                    case "4"://学习管理  StudyActivity
                        MobclickAgent.onEvent(getActivity(), "xuexi");
                        Intent intent_study = new Intent(getActivity(), Study_GuoDuActivity.class);
                        startActivity(intent_study);
                        break;
                    case "3"://活动管理
                        MobclickAgent.onEvent(getActivity(), "huodong");
                        Intent intent_hd = new Intent(getActivity(), HuoDongActivity.class);
                        startActivity(intent_hd);
                        break;
                    case "11"://寿险通
                        MobclickAgent.onEvent(getActivity(), "shouxiantong");
                        Intent intent_sxt = new Intent(getContext(), BannerWebActivity.class);
                        intent_sxt.putExtra("contentsrc", C.sxturl);
                        intent_sxt.putExtra("type", "sxt");
                        intent_sxt.putExtra("name", "");
                        intent_sxt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        getActivity().startActivity(intent_sxt);
                        break;
                    case "10"://掌中宝
                        MobclickAgent.onEvent(getActivity(), "zhangzhongbao");
                        Intent intent_zzb = new Intent(getActivity(), BannerWebActivity.class);
                        intent_zzb.putExtra("contentsrc", C.zzburl);
                        intent_zzb.putExtra("type", "zzb");
                        intent_zzb.putExtra("name", "");
                        intent_zzb.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        getActivity().startActivity(intent_zzb);
                        break;
                    case "12"://档案
                        MobclickAgent.onEvent(getActivity(), "baoxiandangan");
                        Intent intent_jl = new Intent(getActivity(), InsuranceActivity.class);
                        getActivity().startActivity(intent_jl);
                        break;
                    case "13"://工作日志
                        MobclickAgent.onEvent(getActivity(), "gongzuorizhi");
                        Intent intent_worklog = new Intent(getActivity(), WorkListActivity.class);
                        getActivity().startActivity(intent_worklog);
                        break;
                    case "14"://长知识
                        MobclickAgent.onEvent(getActivity(), "zhangzhishi");
                        Intent intent_know = new Intent(getActivity(), ClassroomActivity.class);
                        getActivity().startActivity(intent_know);
                        break;
                    case "15"://获客
                        MobclickAgent.onEvent(getActivity(), "huoke");
                        if (userBe != null) {
                            if (userbean.getIsPay() != null) {
                                Intent intent_huike = new Intent(getActivity(), HuokeListActivity.class);
                                getActivity().startActivity(intent_huike);
                            } else {
                                Toast.makeText(getActivity(), "请支付后进入", Toast.LENGTH_SHORT).show();
                            }
                        }
                        break;
                    case "16"://考勤签到
                        MobclickAgent.onEvent(getActivity(), "qiandao");
                        if (userBe != null) {
                            if (userBe.getIsPay() != null && "1".equals(userBe.getIsPay())) {
                                startActivity(new Intent(getActivity(), SigninTwoActivity.class));
                            } else {
                                Toast.makeText(getActivity(), "请支付后进入", Toast.LENGTH_SHORT).show();
                            }
                        }
                        break;
                    case "17"://dudao
                        MobclickAgent.onEvent(getActivity(), "dudao");
                        startActivity(new Intent(getActivity(), DuDaoLieBiao.class));
                        break;
                    case "18"://dudao
                        MobclickAgent.onEvent(getActivity(), "nimingjubao");
                        startActivity(new Intent(getActivity(), NimingjubaoActivity.class));
                        break;
                    case "19"://dudao
                        MobclickAgent.onEvent(getActivity(), "mingpian");
                        if (SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing() != null && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("")
                                && !SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing().equals("false")) {
                            Intent in = new Intent();
                            in.putExtra("contentsrc", SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getyaoqing());
                            in.putExtra("type", "yaoqing");
                            in.putExtra("people", name);
                            in.putExtra("name", "名片");
                            in.putExtra("touxiang", touxiang);
                            in.setClass(getActivity(), BannerWebActivity.class);
                            startActivity(in);
                        } else {
                            startActivity(new Intent(getActivity(), MingPianActivity.class));
                        }

                        break;
                    case "20"://dudao
                        MobclickAgent.onEvent(getActivity(), "youxi");
                        try {
                            String mtime = makeTime.mtime();
                            String aes = AesUtils.encryptAES(mtime, "1234567812345678");
                            String url = C.ip + C.port + "/app/recreation/recreation/loadRecreation?timestamp=" + aes + "&token=" + token;
                            Intent youxi = new Intent(getActivity(), BannerWebActivity.class);
                            youxi.putExtra("contentsrc", url);
                            youxi.putExtra("name", "游戏");
                            youxi.putExtra("type", "youxi");
                            youxi.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(youxi);
                        } catch (Exception e) {

                        }


                        break;
                    case "21"://baodan
                        MobclickAgent.onEvent(getActivity(), "baodantuoguan");
                        Intent in = new Intent();
                        in.setClass(getActivity(), BaoDanKeHuList.class);
                        startActivity(in);

                        break;
                    case "22"://yejichaxun
                        MobclickAgent.onEvent(getActivity(), "yejichaxun");
                        Intent in_yeji = new Intent();
                        in_yeji.setClass(getActivity(), YeJiChaXunList.class);
                        startActivity(in_yeji);

                        break;
                }
            }
        } else if (parent == pageListview) {
            String type = pageList.get(position).getfTableName();
            switch (type) {
                case "learn"://学习
                    if (pageList.get(position).getLearn() != null) {
                        if (pageList.get(position).getLearn().getLearnType() != null) {
                            String learnType = pageList.get(position).getLearn().getLearnType();
                            if ("video/mp4".equals(learnType)) {//视频
                                Intent intent = new Intent(getActivity(), VideoActivity.class);
                                intent.putExtra("id", pageList.get(position).getLearn().getId());
                                startActivity(intent);
                            } else if ("application/pdf".equals(learnType)) {//PDF
                                Intent intent = new Intent(getActivity(), PdfDetialActivity.class);
                                intent.putExtra("id", pageList.get(position).getLearn().getId());
                                startActivity(intent);
                            } else if ("audio/mp3".equals(learnType)) {//音频
                                Intent intent = new Intent(getActivity(), FrequencyActivity.class);
                                intent.putExtra("id", pageList.get(position).getLearn().getId());
                                startActivity(intent);
                            }
                        }
                    }
                    break;
                case "event"://活动
                    if (pageList.get(position).getEvent() != null) {
                        if (pageList.get(position).getEvent().getEventSrc() != null) {
                            Intent intent = new Intent(getActivity(), BannerWebActivity.class);
                            intent.putExtra("contentsrc", pageList.get(position).getEvent().getEventSrc());
                            intent.putExtra("type", "hd");
                            intent.putExtra("name", pageList.get(position).getEvent().getTtitle());
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    }
                    break;
                case "oaNotify"://消息
                    if (pageList.get(position).getOaNotify() != null) {
                        if (pageList.get(position).getOaNotify().getId() != null) {
                            String ids = pageList.get(position).getOaNotify().getId();
                            String types = "";
                            if (pageList.get(position).getOaNotify().getType() != null) {
                                types = pageList.get(position).getOaNotify().getType();
                            }
                            Intent intent = new Intent(getActivity(), MessageDetilActivity.class);
                            intent.putExtra("ids", ids);
                            intent.putExtra("type", types);
                            startActivity(intent);
                        }
                    }
                    break;
            }
        }
    }

    /**
     * banner图
     *
     * @param result
     */
    @Override
    public void getBannerMessage(PageMessageBean result) {

        if (result != null && !result.equals("")) {
            pageXrefresh.setLoadComplete(false);

            bannerBean = result.getList();
            infos = new ArrayList<ADInfo>();
            for (int i = 0; i < bannerBean.size(); i++) {
                ADInfo info = new ADInfo();
                String url = C.qiniu_ip + bannerBean.get(i).getPicture();
                info.setUrl(url);
                info.setContent("top-->" + i);
                infos.add(info);
            }
            adView.setImageResources(infos, mAdCycleViewListener);
        }
    }

    @Override
    public void getOFO(ShouyeOFOBean result) {

        if (result.getLearn() != null && !result.getLearn().equals("")) {
            ofolin.setVisibility(View.VISIBLE);
            bean = result;
            animationDrawable = (AnimationDrawable) getResources().getDrawable(
                    R.drawable.shouyedonghua);
            ofoimg.setBackground(animationDrawable);
            animationDrawable.start();
            ofotitle.setText(result.getLearn().getTitle());
        } else {
            ofolin.setVisibility(View.GONE);
        }

    }


    /**
     * 首页所有应用
     *
     * @param result
     */
    @Override
    public void getAPPactionMessage(List<String> result) {
        pageXrefresh.stopRefresh();
        if (result != null && result.size() > 0) {
            app_List = new ArrayList<>();
            app_List = result;

            for (int i = 0; i < app_List.size(); i++) {
                if (app_List.get(i).equals("19")) {
                    pagePresenter.getshouyemingpianinfo(token);
                } else {
                }
                if (app_List.get(i).length() > 2) {
                    app_List.remove(i);
                    i--;
                }
            }
            adapter.setList(app_List, size);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("applist", result);
            String app = JsonUtils.toJson(map);
            if (app != null && !"".equals(app)) {
                SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setAppaction(app);
            }
        }
    }

    @Override
    public void getyaoqinginfo(MingpianBean result) {
        if (result != null && !result.equals("")) {
            name = result.getName();
            touxiang = result.getImage();
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setyaoqing(result.getUrl());
        } else {
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setAppaction("false");
        }

    }


    /**
     * 应用列表
     *
     * @param result
     */
    @Override
    public void getPageList(PageListBean result) {
        pageList = new ArrayList<>();
        pageList = result.getList();
        if (pageList != null) {
            listAdapter.setLists(pageList);
        }
    }

    /**
     * 进首页获取个人信息
     *
     * @param result
     */
    @Override
    public void getPageUser(UsersBean result) {
        if (result != null) {
            userBe = result;
            if (userBe.getIsNeedPay().getIsNeedPay() != null && userBe.getIsNeedPay().getIsNeedPay().equals("0")) {
                userBe.setIsPay("1");
                String s = new Gson().toJson(userBe);
                CommonUtils.dakaMap.put("s", s);
            } else {
                String s = new Gson().toJson(userBe);
                CommonUtils.dakaMap.put("s", s);
            }
            if (MapUtils.getString(CommonUtils.dakaMap, "s") != null) {
                SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setUserMessage(MapUtils.getString(CommonUtils.dakaMap, "s"));
            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        String app = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getAppaction();
        size = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getAppactionnum();
        MobclickAgent.onResume(getActivity());
        if (app == null || "".equals(app)) {
            initadapter();
        } else {
            initData();
        }
    }

    @Override
    public void erroy() {
        if (getActivity() != null)
            ToastUtil.show(getActivity(), "请求失败，请重试！");
    }

    @Override
    public void erry(String result) {
        if (getActivity() != null)
            if (result != null) {
                if (result.equals("tiaoguo")) {
                } else {
                    ToastUtil.show(getActivity(), result + "");
                }

            }
        if (result.contains("过期")) {
            getActivity().getSharedPreferences("appbase", Context.MODE_PRIVATE).edit().clear().commit();
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().SetLogin(false);
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setIsFirst(true);
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            startActivity(intent);
//            AppManager appManager = AppManager.getAppManager();
//            appManager.finishAllActivity();
            getActivity().finish();
        }
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onRefresh(boolean isPullDown) {
        lastRefreshTime = pageXrefresh.getLastRefreshTime();
        pageXrefresh.restoreLastRefreshTime(lastRefreshTime);
        if (isNetWork()) {
            initadapter();
            getList();

//            getUsers();
        }
    }

    @Override
    public void onLoadMore(boolean isSilence) {
        pageXrefresh.stopLoadMore();
    }

    @Override
    public void onRelease(float direction) {
//        if (direction > 0) {
//            Log.d("mwh", "下拉");
//        } else {
//            Log.d("mwh", "上拉");
//        }
    }

    @Override
    public void onHeaderMove(double headerMovePercent, int offsetY) {

    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(getActivity());
    }

    @Override
    public void onDestroy() {
        if (animationDrawable != null) {
            animationDrawable.stop();
        }
        pagePresenter.onDestory();

        super.onDestroy();
    }
}
